using UnityEngine;

namespace MaterialUI
{
	public static class GameObjectExtension
	{
		public static T GetAddComponent<T>(this GameObject gameObject) where T : Component
		{
			if ((Object)gameObject.GetComponent<T>() != (Object)null)
			{
				return gameObject.GetComponent<T>();
			}
			return gameObject.AddComponent<T>();
		}

		public static T GetChildByName<T>(this GameObject gameObject, string name) where T : Component
		{
			T[] componentsInChildren = gameObject.GetComponentsInChildren<T>(includeInactive: true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				if (componentsInChildren[i].name == name)
				{
					return componentsInChildren[i];
				}
			}
			return (T)null;
		}
	}
}
